package com.dinim.test.objectlibrary;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.dinim.common.StopWatch;
import com.dinim.graphics.IGraphicsContext;
import com.dinim.object.IObject2D;
import com.dinim.object.ITransformable;
import com.dinim.object.Object2D;
import com.dinim.object.Point2D;
import com.dinim.object.Rectangle2D;
import com.dinim.physics2D.Aabb;
import com.dinim.physics2D.AabbSingleBoundingBox;
import com.dinim.physics2D.BoundingBox2D;
import com.dinim.physics2D.IBoundingBox2D;
import com.dinim.test.TestApplication;

public class ObjectsWithIntersectionsTester extends TestApplication{

    private List objects = new ArrayList();
    private int objCount = 2;
    private Aabb aabb = new AabbSingleBoundingBox(width, height, 10, 10);
    
    public static void main(String[] args) {
        ObjectsWithIntersectionsTester owit = new ObjectsWithIntersectionsTester();
        owit.showForm();
    }

    public ObjectsWithIntersectionsTester(){
        
        for(int i = 0; i < objCount; i++){
            double x = randomizer.nextInt(width-100)+50;
            double y = randomizer.nextInt(width-100)+50;
            Rectangle2D rect = new Rectangle2D(x, y, x + randomizer.nextInt(2)+4, y + randomizer.nextInt(2)+4);
            rect.rotate(randomizer.nextInt()+10, new Point2D(width/2,height/2));
            objects.add(rect);
        }
        
        for(int u = 0; u < 10; u++){
            StopWatch sw = new StopWatch();
            sw.start();
            for(int i = 0; i < objects.size(); i++){
//                double x = randomizer.nextInt(width-100)+50;
//                double y = randomizer.nextInt(width-100)+50;
//                Rectangle2D rect = new Rectangle2D(x, y, x + randomizer.nextInt(2)+4, y + randomizer.nextInt(2)+4);
//                objects.add(rect);
//                rect.rotate(randomizer.nextInt()+10, new Point2D(width/2,height/2));

//                aabb.addBoundingBox(((IObject2D)objects.get(i)).getBoundingBox());
                List boxes = ((IObject2D)objects.get(i)).getLineBoundingBoxes(4);
                Iterator it = boxes.iterator();
                while(it.hasNext()){
                    //aabb.addBoundingBox((IBoundingBox2D)it.next());
                }
            }
            //System.out.println(aabb.toString());
            sw.stop();
            System.out.println(sw.getElapsedTime());
        }
    }
    
    public void paintSomething(IGraphicsContext gc) {
        Iterator i = objects.iterator();
        while(i.hasNext()){
            Object2D obj = (Object2D)i.next();
            obj.draw(gc);
//            List boxes = aabb.getBoundingBoxes();
//            Iterator it = boxes.iterator();
//            while(it.hasNext()){
//                BoundingBox2D bb = ((BoundingBox2D)it.next());
//                bb.draw(gc);
//                //System.out.println(bb);
//            }
        }
        //aabb.draw(gc);
    }
}
